home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / VideoToolbox 97.08.16 / VideoToolboxSources / ChooseScreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-10  |  1.8 KB  |  67 lines  |  [TEXT/CWIE]

  1. /*
  2. ChooseScreen.c
  3.  
  4. Displays a screen number on every screen, and accepts the typed selection from
  5. the user, using the argument value as the default. No check is made for
  6. validity of the default or the reply.
  7.     screen=1;
  8.     screen=ChooseScreen(screen,"Which screen?");
  9.  
  10. HISTORY:
  11. 9/5/94 dgp removed assumption in printf's that int==short.
  12. 10/2/94 dgp added question argument.
  13. 1/5/95    dgp made compatible with Universal Headers 2.
  14. 4/10/97    dgp    Eliminate stuff that was conditional on !UNIVERSAL_HEADERS.
  15. */
  16. #include "VideoToolbox.h"
  17. #include <LowMem.h>    // LMSetGhostWindow
  18.  
  19. int ChooseScreen(int screen,const char *question)
  20. {
  21.     short i,fontNumber,textSize;
  22.     Rect r;
  23.     GDHandle device=NULL,oldDevice=NULL;
  24.     WindowPtr window=NULL,oldWindow=NULL,windows[MAX_SCREENS];
  25.     unsigned char string[16]="\p0";
  26.     char str[32];
  27.     FontInfo fontInfo;
  28.     long ticks;
  29.  
  30.     oldDevice=GetGDevice();
  31.     SetGDevice(GetMainDevice());
  32.     GetPort(&oldWindow);
  33.     ticks=TickCount();
  34.     for(i=0;i<MAX_SCREENS;i++){
  35.         device=GetScreenDevice(i);
  36.         if(device == NULL)break;
  37.         SetRect(&r,0,0,160,160);
  38.         CenterRectInRect(&r,&(*device)->gdRect);
  39.         string[1]='0'+i;
  40.         windows[i]=NewWindow(NULL,&r,string,TRUE,plainDBox,(WindowPtr) -1L,0,0);
  41.         SetPort(windows[i]);
  42.         if(i==0)GetFNum("\pChicago",&fontNumber);
  43.         TextFont(fontNumber);
  44.         textSize=128;
  45.         TextSize(textSize);
  46.         if(i==0)GetFontInfo(&fontInfo);
  47.         SetRect(&r,0,0,StringWidth(string),fontInfo.ascent);
  48.         CenterRectInRect(&r,&windows[i]->portRect);
  49.         MoveTo(r.left,r.bottom);
  50.         DrawString(string);
  51.     }
  52.     LMSetGhostWindow((WindowRef)windows[0]);    // doesn't work; don't know why.
  53.     SetPort(oldWindow);
  54.     SetGDevice(oldDevice);
  55.     ticks=ticks+50-TickCount();
  56.     if(ticks>0)Delay(ticks,&ticks);
  57.     printf("%s (%d):",question,screen);
  58.     gets(str);
  59.     sscanf(str,"%d",&screen);
  60.     for(i=0;i<MAX_SCREENS;i++){
  61.         device=GetScreenDevice(i);
  62.         if(device==NULL)break;
  63.         DisposeWindow(windows[i]);
  64.     }
  65.     return screen;
  66. }
  67.